package sample.servlet;

import fri.entiry.FrUser;
import fri.businessLayer.UserBeanRemote;
import java.io.IOException;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SearchController extends HttpServlet {

    @EJB
    private UserBeanRemote userBeanRemote;
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String action = request.getParameter("action");
            if (action != null) {
                if (action.equals("search")) {
                    String txtSearch = request.getParameter("txtSearch");
                    List<FrUser> lstFrUser = userBeanRemote.getUserByFullName(txtSearch);
                    request.setAttribute("lstFrUser", lstFrUser);
                    RequestDispatcher rd = request.getRequestDispatcher("reqSearch.jsp");
                    rd.forward(request, response);
                }
            }
            RequestDispatcher rd = request.getRequestDispatcher("reqSearch.jsp");
            rd.forward(request, response);
        } finally {
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }
}
